package com.fs.spring.test.aop.monitor;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author shuai.fang
 * @date：2017-08-10
 * @description：
 */
public class PerformanceMonitor {

	private static Logger logger = LoggerFactory.getLogger(PerformanceMonitor.class);

	private static ThreadLocal<MethodPerformance> performanceRecord = new ThreadLocal<MethodPerformance>();

	public static void begin(String method) {
		MethodPerformance methodPerformance = new MethodPerformance();
		methodPerformance.setStart(System.currentTimeMillis());
		methodPerformance.setMethod(method);
		performanceRecord.set(methodPerformance);
	}

	public static void end() {
		MethodPerformance methodPerformance = performanceRecord.get();
		methodPerformance.setEnd(System.currentTimeMillis());
		logger.info("method -> {}, 执行时间 -> 【{}】毫秒", methodPerformance.getMethod(), methodPerformance.elapsed());
	}
}
